<template>
	<view class="padding30rpx">
		<view class="dis align-items line adit">
			<view>头像</view>
			<u-avatar :src="data.headimg" @click="change"></u-avatar>
		</view>
		<view class="dis align-items line adit">
			<view>昵称</view>
			<input class="hui66" style="width: 160rpx;text-align: right;" type="text" value=""
				v-model="data.likename" />
		</view>
		<view class="dis align-items line adit">
			<view>姓名</view>
			<input class="hui66" style="width: 190rpx;text-align: right;" type="text" value=""
				v-model="data.username" />
		</view>
		<view class="dis align-items line adit">
			<view>性别</view>
			<view class="hui66">{{data.sex||'男'}}</view>
		</view>
		<view class="dis align-items line adit" @click.stop="showBirthday=true">
			<view>生日</view>
			<!-- <view class="hui66">{{data.birthday||'请选择'}}</view> -->
			<view>
				<u-input @click="showBirthday=true" v-model="data.birthday" input-align='right' height="35"
					type="select" placeholder="请选择" />
			</view>
		</view>
		<view class="dis align-items line adit">
			<view>企业名称</view>
			<input class="hui66" style="width: 220rpx;text-align: right;" type="text" value=""
				v-model="data.enterprisename" />
		</view>
		<view class="dis align-items line adit">
			<view>所属门店</view>
			<input class="hui66" style="width: 220rpx;text-align: right;" type="text" value="" v-model="data.store" />
		</view>
		<view class="dis align-items line adit">
			<view>门店地址</view>
			<input class="hui66" style="text-align: right;" type="text" value="" v-model="data.address" />
		</view>
		<view class="dis align-items line adit">
			<view>所在部门</view>
			<input class="hui66" style="text-align: right;" type="text" value="" v-model="data.department" />
		</view>
		<!-- <view class="dis align-items line adit">
			<view>当前岗位</view>
			<view class="dis align-items">
				<input class="hui66" style="text-align: right;" placeholder="选择岗位" disabled type="text" value="" v-model="data.station" />
				<image src="../../static/user/right.png" style="width: 15rpx;height: 28rpx;margin-left: 15rpx;"></image>
			</view>
		</view> -->
		<view class="dis align-items line adit" @click.stop="ruzhuTime=true">
			<view>入职年份</view>
			<!-- <view class="hui66">{{data.employment||''}}</view> -->
			<view>
				<u-input @click="ruzhuTime=true" v-model="data.employment" input-align='right' height="35" type="select"
					placeholder="请选择" />
			</view>
		</view>
		<view class="dis align-items line adit">
			<view>手机号</view>
			<view class="dis align-items">
				<view class="hui66">{{data.phone||'未绑定'}}</view>
				<image src="../../static/user/right.png" style="width: 15rpx;height: 28rpx;margin-left: 15rpx;"></image>
			</view>
		</view>
		<view class="dis align-items line adit">
			<view>微信绑定</view>
			<view class="hui66 dis align-items" v-if="data.openid != null">
				已绑定
				<image src="../../static/user/right.png" style="width: 15rpx;height: 28rpx;margin-left: 15rpx;"></image>
			</view>
			<!-- <view class="hui66 dis align-items" v-else @click="wxLogin">
				未绑定
				<image src="../../static/user/right.png" style="width: 15rpx;height: 28rpx;margin-left: 15rpx;"></image>
			</view> -->
		</view>
		<u-picker mode="time" v-model="showBirthday" @confirm="timeReturn"></u-picker>
		<u-picker mode="time" v-model="ruzhuTime" :params="params" @confirm="ruzhiTimeReturn"></u-picker>
		<button @tap="enter">保存</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showBirthday: false, //生日时间
				ruzhuTime: false, //入职时间
				data: {
					// headimg: 'https://pic2.zhimg.com/80/v2-da2b0a3b96103d87a682409fc5a261a9_720w.jpg',
					// name: '郑希前',
					// nickName: 'Jessica',
					// sex: '男',
					// birthday: '1998-04-01',
					// enterprisename: '零商e学',
					// department: '零商e学',
					// address: '贵阳市南明区花果园国际中心',
					// type: '产品',
					// Rnew: '2000年',
					// mobile: '1888****8888',
					// wx: ''
				},
				params: {
					year: true,
					month: true,
					day: false,
				},
				action: this.$api + '/app/fileUpController/fileUP',
				fileList: []
			}
		},
		onLoad() {
			this.selectUserMassges()
		},
		methods: {
			//时间选择
			timeReturn(e) {
				this.data.birthday = this.timeset(e);
			},
			ruzhiTimeReturn(e) {
				this.data.employment = this.timeset(e);
			},
			timeset(e) {
				let time = ''
				if (e.year) time += e.year
				if (e.month) time += '-' + e.month
				if (e.day) time += '-' + e.day
				if (e.hour) time += ' ' + e.hour
				if (e.minute) time += ':' + e.minute
				if (e.second) time += ':' + e.second
				return time;
			},
			selectUserMassges() {
				uni.request({
					method: 'GET',
					url: this.$api + '/app/UserController/selectUserMassges',
					header: {
						'token': uni.getStorageSync('token')
					},
					success: (res) => {
						console.log('查询用户信息', res.data)
						if (res.data.code == 200) {
							this.data = res.data.data
						}
						if (res.data.code == 401) {
							uni.navigateTo({
								url: '/pagesB/login/login'
							})
						}
					}
				})
			},

			succ(e) {
				console.log('----', e)
				this.data.headimg = e
			},
			change(e) {
				console.log(uni.getStorageSync('token'))
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album'], //从相册选择
					success: (res) => {
						const tempFile = res.tempFilePaths
						// console.log('拿到的图片',tempFile)
						uni.uploadFile({
							url: this.$api + '/app/fileUpController/fileUP',
							// header:{'token':uni.getStorageSync('token')},
							filePath: tempFile[0],
							name: 'file',
							formData: {
								// 'username':this.userInfo.username   //formData是指除了图片以外，额外加的字段
							},
							success: (reson) => {
								var obj = reson
								console.log('reson.data', obj)
								this.data.headimg = obj.data
							}
						})
					}
				})
			},
			//保存
			enter() {
				uni.request({
					method: 'POST',
					url: this.$api + '/app/UserController/updateUser',
					data: {
						"address": this.data.address,
						"birthday": this.data.birthday,
						"characters": this.data.characters,
						"department": this.data.department,
						"employment": this.data.employment,
						"enterprisename": this.data.enterprisename,
						"headimg": this.data.headimg,
						"likename": this.data.likename,
						"openid": this.data.openid,
						"phone": this.data.phone,
						"sex": this.data.sex,
						"store": this.data.store,
						"username": this.data.username
					},
					header: {
						'token': uni.getStorageSync('token')
					},
					success: (res) => {
						console.log(res.data)
						if (res.data.code == 200) {
							uni.showToast({
								icon: 'none',
								title: '保存成功'
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							})
						}
					},
					fail: (err) => {
						console.log(err)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}

	.adit {
		// margin-top: 30rpx;
		padding: 30rpx 0;
	}

	button {
		width: 100%;
		background: #00a29a;
		height: 92rpx;
		line-height: 92rpx;
		margin-top: 100rpx;
		margin-bottom: 80rpx;
		color: #FFFFFF;
	}
</style>
